$(document).ready(function(e){
    $('.page-membership #rapids .package').click(function(e){
       e.preventDefault();
       $data_nid = $(this).attr('name').split('-');
       if($data_nid[1] == 'blue')
       {
         location.href = Drupal.settings.basePath+'node/add/property';
       }
       else
       {
        
        function date_reload(data)
        {
           if(data.reply == 1)
           {
             location.href = Drupal.settings.basePath +'cart/checkout';
           }
           else
           {
             alert('An error has occured, please try again');
           }
         
        }
          $.ajax({
             type: 'POST', // Use the POST method.
             url:Drupal.settings.basePath+'add_cart_items',
             success:date_reload,
             dataType: 'json',
             data:'cart_item='+$data_nid[1]
         });
         
        } 
    });
    
    $('.page-cart-checkout .rate-policies .checkout_finish').click(function(e){
       $('.page-cart-checkout form#uc-cart-checkout-form').submit(); 
    });
     $('.page-cart-checkout-review').ready(function(e){
       $('.page-cart-checkout-review form#uc-2checkout-form').submit(); 
    });
    
    $('#user-register #edit-submit').click(function(){
        $('#edit-pass-pass1, #edit-pass-pass2').val($('#edit-defopass').val());
        $('#edit-title,#edit-name').val($('#edit-mail').val());
    });
    
    $('#block-custom-islands_name_description .island li a').click(function(e){
        e.preventDefault();
        $('#block-custom-islands_name_description .island li a').removeClass('active');
        $(this).addClass('active'); rel = $(this).attr('rel');
        $('#block-custom-islands_name_description .overview div').fadeOut();
        $('#block-custom-islands_name_description .overview div[rel='+ rel +']').fadeIn();
    });
    
    /**** Gmap link ******/
    
    $('.login-area .login_button a').click(function(e){
       e.preventDefault();
       $('.login-area .login-member').slideToggle('500');
       if($('.login-area .login-member').css('display') == 'none')
       {
        $('#header .membership').show();
       }
       else if($('.login-area .login-member').css('display') == 'block')
       {
         $('#header .membership').hide();
       }
       
    });
    
    /* Add property */
    $('#large .rate .form-radios input').change(function() {
        $('#large .policies').fadeIn();
        nobeds = $('#edit-field-pro-beds-value').val();
        if ( nobeds > 1) {
            $('#nobeds').html(nobeds + ' beds');
        } else {
            $('#nobeds').html('1 bed');
        }
        if ($(this).val() == 1) {
            $('#ratetype').html('Nightly rates');
        }
        if ($(this).val() == 2) {
            $('#ratetype').html('Weekly rates');
        }
        if ($(this).val() == 3) {
            $('#ratetype').html('Monthly rates');
        }
    });
    $('#edit-field-pro-beds-value').change(function(){
        nobeds = $(this).val();
        if ( nobeds > 1) {
            $('#nobeds').html(nobeds + ' beds');
        } else {
            $('#nobeds').html('1 bed');
        }
    });
    
    /*** Property search ***/
    //sorting
    $('.d_down select').change(function(){
       $currenturl = window.location.href.split('?');
       window.location.href = $currenturl[0] + '?sort=' + $(this).val();
    });
    //Filtering
    $('.checkbox .dummy').change(function(){
        if ($(this).is('input:checked')) {
            $(this).siblings('.iamit').find('input').val('1');
        }
        else {
            $(this).siblings('.iamit').find('input').val('');
        }
    });
    
    // One image in property page
    $('.node-type-property .property-thumbnails a').hover(function(e){
       e.preventDefault();
       var href=Drupal.settings.basePath + $(this).attr('name');
       $('.node-type-property .property-images img').fadeIn();
       $('.node-type-property .property-images img').attr('src',href);
       
       
    });
});